package com.licheng.service.imp;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.licheng.mapper.ClazzMapper;
import com.licheng.mapper.EmpMapper;
import com.licheng.mapper.OperateLogMapper;
import com.licheng.mapper.StudentMapper;
import com.licheng.pojo.*;
import com.licheng.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private ClazzMapper clazzMapper;
    @Autowired
    private OperateLogMapper operateLogMapper;

    /**
     * 统计职位人数
     *
     * @return
     */
    @Override
    public JobOption empJobData() {
        List<Map> jobOption = empMapper.empJobData();

        List<Object> jobList = jobOption.stream().map(map -> {
            return map.get("pos");
        }).collect(Collectors.toList());

        List<Object> dataList = jobOption.stream().map(map -> {
            return map.get("posCount");
        }).collect(Collectors.toList());

        return new JobOption(jobList, dataList);
    }

    /**
     * 统计员工性别数量
     *
     * @return
     */
    @Override
    public List<Map> empGender() {
        List<Map> genderOption = empMapper.empGender();
        return genderOption;
    }

    /**
     * 统计学员学历
     *
     * @return
     */
    @Override
    public List<Map> studentDegreeData() {
        List<Map> degreeList = studentMapper.studentDegreeData();
        return degreeList;
    }

    /**
     * 统计班级人数
     *
     * @return
     */
    @Override
    public ClazzCountOption studentCountData() {
        List<Map> mapList = clazzMapper.studentCountData();

        List<Object> clazzList = mapList.stream().map(map -> {
            return map.get("clazzName");
        }).toList();

        List<Object> dataList = mapList.stream().map(map -> {
            return map.get("clazzCount");
        }).toList();

        return new ClazzCountOption(clazzList, dataList);
    }

    /**
     * 日志列表查询
     * @param logPageQuery
     * @return
     */
    @Override
    public LogPageResult logPageSelect(LogPageQuery logPageQuery) {
        PageHelper.startPage(logPageQuery.getPage(), logPageQuery.getPageSize());

        List<OperateLog> operateLogList = operateLogMapper.logPageSelect();

        Page p = (Page) operateLogList;
        long total = p.getTotal();
        List<OperateLog> rows = p.getResult();
        return new LogPageResult(total, rows);
    }
}
